package leetcode.method.pointer;

import java.util.ArrayList;
import java.util.List;

public class Program228SummaryRange {

    public Program228SummaryRange() {
    }


    public List<String> summaryRanges(int[] nums) {
        List<String> res = new ArrayList<>();
        if (nums.length == 0) {
            return res;
        }
        int i = 0,j = 1;
        while (j < nums.length) {
            if (j - i != nums[j] - nums[i]) {
                res.add(j - 1 == i ? String.valueOf(nums[i]) : nums[i] + "->" + nums[j - 1]);
                i = j;
            }
            j++;
        }

        if (j == nums.length) {
            res.add(j-1 == i ? String.valueOf(nums[i]) : nums[i] + "->" + nums[j-1]);
        }
        return  res;
    }

    public static void main(String[] args) {
        Program228SummaryRange myStack = new Program228SummaryRange();
        int[] nums = new int[]{0,2,3,4,6,8,9};
        System.out.println(myStack.summaryRanges(nums));
        int[] nums1 = new int[]{0,1,2,4,5,7};
        System.out.println(myStack.summaryRanges(nums1));
    }
}
